package com.woniu.zsd.merchant.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.dto.ReplyListDto;
import com.woniu.form.AddCommentForm;
import com.woniu.form.QueryReplyForm;
import com.woniu.zsd.commons.core.model.Result;
import com.woniu.zsd.merchant.service.IReplyService;
import com.woniu.zsd.merchant.util.MerchartTokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-27
 */
@RestController
@RequestMapping("/reply")
@Api(tags = "回复业务")
public class ReplyController {
    @Autowired
    private IReplyService replyService;
    @Autowired
    private MerchartTokenUtil tokenUtil;

    @ApiOperation(value = "查询回复信息")
    @GetMapping("/list")
    public Result<Page<ReplyListDto>> replyList(@Valid QueryReplyForm queryReplyForm) {
        Page<ReplyListDto> replyListDto = replyService.replyList(queryReplyForm);
        return new Result<Page<ReplyListDto>>().setCode(200).setMsg("查询回复成功").setData(replyListDto);
    }

    @ApiOperation(value = "添加评论")
    @GetMapping("/add/comment")
    public Result addComment(@Valid AddCommentForm addCommentForm, @RequestHeader String token) {

        replyService.addComment(addCommentForm, token);
        return Result.getResult().setCode(200).setMsg("添加站点评论成功");
    }

    @ApiOperation(value = "删除评论")
    @DeleteMapping("/delete/comment")
    public Result deleteComment(
            @ApiParam(value = "公告id列表") @RequestParam Integer id,
            @ApiParam(value = "发布人id") @RequestHeader String token
    ) {

        replyService.deleteReply(id, token);
        return Result.getResult().setCode(200).setMsg("删除成功");
    }
}